package com.cwvs.cat.bean;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;



public class ActiveContent {
	public String id;
	public String org_id;
	public String category;
	public String categoryname;
	public String owner;
	public String ownername;
	public String created;
	public String begin_time;
	public String title;
	public String content;
	public String ps_count;
	public String reality_ps_count;
	public String pic;
	public String sign_count;
	public String location_x;
	public String location_y;
	public String location;
	public String status;
	public String is_join= "";
	public String is_sign= "";
	public ActiveContent(){

	}

	public ActiveContent(List<String> list){
		this.id = list.get(0);
		this.org_id = list.get(1);
		this.category = list.get(2);
		this.categoryname = list.get(3);
		this.owner = list.get(4);
		this.ownername = list.get(5);
		this.created = list.get(6);
		this.begin_time = list.get(7);
		this.title = list.get(8);
		this.content = list.get(9);
		this.ps_count = list.get(10);
		this.reality_ps_count = list.get(11);
		this.pic = list.get(12);
		switch (list.size()) {
		case 17:
			this.location_x = list.get(13);
			this.location_y = list.get(14);
			this.location = list.get(15);
			this.status = list.get(16);
			break;
		case 18:
			this.location_x = list.get(13);
			this.location_y = list.get(14);
			this.location = list.get(15);
			this.status = list.get(16);
			this.is_join = list.get(17);
			break;
		case 20:
			this.sign_count = list.get(13);
			this.location_x = list.get(14);
			this.location_y = list.get(15);
			this.location = list.get(16);
			this.status = list.get(17);
			this.is_sign = list.get(18);
			this.is_join = list.get(19);
			break;
		default:
			break;
		}
	}

	public void fromJson(JSONObject json){
		id = json.optString("id");
		org_id = json.optString("org_id");
		category = json.optString("category");
		categoryname = json.optString("categoryname");
		owner = json.optString("owner");
		ownername = json.optString("ownername");
		created = json.optString("created");
		begin_time = json.optString("begin_time");
		title = json.optString("title");
		content = json.optString("content");
		ps_count= json.optString("ps_count");
		reality_ps_count = json.optString("reality_ps_count");
		
		pic = json.optString("pic");
		location_x = json.optString("location_x");
		location_y = json.optString("location_y");
		location = json.optString("location");
		status= json.optString("status");
		is_join = json.optString("is_join");
	}
	public JSONObject toJson(){
		JSONObject json = new JSONObject();
		try {
			json.put("id", id);
			json.put("org_id", org_id);
			json.put("category", category);
			json.put("categoryname", categoryname);
			json.put("owner", owner);
			json.put("ownername", ownername);
			json.put("created", created);
			json.put("begin_time", begin_time);
			json.put("title", title);
			json.put("content", content);
			json.put("ps_count", ps_count);
			json.put("reality_ps_count", reality_ps_count);
			json.put("pic", pic);
			json.put("location_x", location_x);
			json.put("location_y", location_y);
			json.put("location", location);
			json.put("status", status);
			json.put("is_join", is_join);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return json;
	}
	public static ActiveContent createFromJson(JSONObject json) {
		ActiveContent user = new ActiveContent();
		user.fromJson(json);
		return user;
	}
}
